package com.bw.sign

import android.widget.TextView
import com.blankj.utilcode.util.ColorUtils
import com.bw.lib_base.entity.SignBeanItem
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class SignAdapter: BaseQuickAdapter<SignBeanItem, BaseViewHolder>(R.layout.item_sign) {
    override fun convert(helper: BaseViewHolder, item: SignBeanItem) {
        if (item.morningCheckIn.isNotEmpty()){
            //切割日期和时间
            val split = item.morningCheckIn.split(" ")
            val date = split[0].split("-")
            helper.setText(R.id.sign_date, "${date[0]+"年"+date[1]+"月"+date[2]+"日"}")

            //设置
            setShow(split, item, helper)
            helper.setText(R.id.sign_time,"${"上班时间："+split[1]}")

        }else if (item.afternoonCheckIn.isNotEmpty()){
            val split = item.afternoonCheckIn.split(" ")
            val date = split[0].split("-")
            helper.setText(R.id.sign_date, "${date[0]+"年"+date[1]+"月"+date[2]+"日"}")
            //设置
            setShow(split, item, helper)
            helper.setText(R.id.sign_time,"${"下班时间："+split[1]}")
        }

    }

    fun setShow(split: List<String>,item: SignBeanItem,helper: BaseViewHolder){
        //设置时间

        helper.setText(R.id.sign_status, item.status)
        helper.setText(R.id.sign_location, item.location)
        helper.getView<TextView>(R.id.sign_status).apply {
            when(item.status){
                "正常" ->{
                    setTextColor(ColorUtils.getColor(R.color.green))
                    setBackgroundResource(R.drawable.shape_status_green)
                }
                "迟到" ->{
                    setTextColor(ColorUtils.getColor(R.color.yellow))
                    setBackgroundResource(R.drawable.shape_status_yellow)
                }
                "早退" ->{
                    setTextColor(ColorUtils.getColor(R.color.blue))
                    setBackgroundResource(R.drawable.shape_status_blue)
                }
                "迟到" ->{
                    setTextColor(ColorUtils.getColor(R.color.red))
                    setBackgroundResource(R.drawable.shape_status_red)
                }

            }
        }
    }
}